package com.hos.config;



import com.hos.interceptor.SessionTimeoutInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Hanyixuan
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    SessionTimeoutInterceptor sessionTimeoutInterceptor;

    /**
     * 释放静态资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/assets/ckeditor/**").
                addResourceLocations("classpath:/static/assets/ckeditor/").
                setCachePeriod(2592000);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/admin").setViewName("admin");
        registry.addViewController("/doctor").setViewName("doctor");
        registry.addViewController("/doctorAdd").setViewName("doctorAdd");
        registry.addViewController("/doctorEdit").setViewName("doctorEdit");
        registry.addViewController("/card").setViewName("card");
        registry.addViewController("/cardAdd").setViewName("cardAdd");
        registry.addViewController("/cardEdit").setViewName("cardEdit");
        registry.addViewController("/patient").setViewName("patient");
        registry.addViewController("/patientAdd").setViewName("patientAdd");
        registry.addViewController("/patientEdit").setViewName("patientEdit");
        registry.addViewController("/message").setViewName("message");
        registry.addViewController("/hospitalStat").setViewName("hospitalStat");
        registry.addViewController("/card001").setViewName("card001");
        registry.addViewController("/card001Edit").setViewName("card001Edit");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(sessionTimeoutInterceptor).addPathPatterns("/**").
                excludePathPatterns("/api/indexcard/*","/api/message/*","/","/index","/login","/admin","/static/**");
    }

}
